home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10668 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news2.noc.netcom.net!news
  2. Newsgroups: comp.lang.c
  3. Subject: Re: goto
  4. Message-ID: <314E0BDE.7933@willows.com>
  5. From: Tarang Deshpande <tarang@willows.com>
  6. Date: Mon, 18 Mar 1996 17:20:30 -0800
  7. References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
  8. Organization: NETCOM Network Operations
  9. NNTP-Posting-Host: daffy.willows.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13.  
  14. Bill Simpson wrote:
  15. > There was a goto thread lately, and my problem is to state this algorithm
  16. > cleanly without gotos (which I think is easy, but my attempts have been
  17. > failures).
  18. > 0. x=0;
  19. > 1. x+=erand(maxmean);
  20. > 2. if (urand2()>rate(x)/maxrate)
  21. >         goto step 1
  22. > 3. if (x<=XMAX)
  23. >         {
  24. >         setdot(x,y,z);
  25. >         goto step 1
  26. >         }
  27. > explanation:
  28. > erand(mean) returns exponential double random number with given mean
  29. > urand2() returns uniform double random number between 0 & 1
  30. > rate(). well the rate of the Poisson process varies with x
  31.  
  32.  
  33. x = 0;
  34. do
  35. {
  36.     double uRand;
  37.     double rateCalc;
  38.  
  39.     x += erand ( maxmean );
  40.     uRand = urand2 ();
  41.     rateCalc = rate ( x ) / maxrate;
  42.     if ( urand <= rateCalc )
  43.         if ( x <= XMAX )
  44.             setdot ( x, y, z );
  45. } while ( ( x > XMAX ) || ( uRand > rateCalc ) );
  46.  
  47.